<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/react/umd/react.development.js"></script>
    <script src="../node_modules/react-dom/umd/react-dom.development.js"></script>
    <script src="../node_modules/babel-standalone/babel.js"></script>
</head>
<body>
    <div id="app"></div>
    <script type="text/babel">
        // 1. onclick => onClick
        // 2. this.a && onClick={函数} 不能是字符串
        // 3. this 的掉失，因为是 JS 引擎调用 fn, 所以 this 无法正确初始化。
        //      ES6: fn.bind(this);
        // 4. state

        class Cmp1 extends React.Component {
            constructor(props) {
                super(props);

                // this.a = 5; 不更新

                this.state = {
                    a: 5
                }
                console.log(this.state.a);
            }

            fn() {
                // this.stte.a++;
                this.setState({
                    a: this.state.a + 1
                });
                console.log(this.state.a);
            }

            render() {
                return (
                    <div>
                        {this.state.a}
                        <input type="button" value="+1" onClick={this.fn.bind(this)} />
                    </div>
                );
            }
        }

        let oDiv = document.getElementById('app');

        ReactDOM.render(
            <Cmp1 />,
            oDiv
        );
    </script>
</body>
</html>